//
//  WPTradeOrderViewModel.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/13.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPTradeOrderPayViewModel.h"

@implementation WPTradeOrderPayViewModel
+ (void)payOrderWithTicketId:(NSNumber *)tickerID pwd:(NSString *)pwd andSuccessBlock:(void (^)(NSString *))success andFailureBlock:(void (^)(NSString *))failure {
    NSDictionary * params = @{@"memberid":[UserModel defaultUser].userID,
                              @"ticket":tickerID,
                              @"pwd":pwd};
    [NetWorkingManager postWithUrl:@"commoditytrade/buy.jhtml" requestParams:[NetWorkingManager paramsByAppendingUserInfo:params] SuccessHandler:^(id responseObject) {
        if (responseObject[@"resultType"]&&[responseObject[@"resultType"] intValue]) {
            if (responseObject[@"resultMsg"]) {
                NSString * name = responseObject[@"resultMsg"][@"name"]?responseObject[@"resultMsg"][@"name"] :@"";
                NSString * mobile = responseObject[@"resultMsg"][@"mobile"] ?
                responseObject[@"resultMsg"][@"mobile"] :@"";
                success([NSString stringWithFormat:@"%@,%@", name, mobile]);
            } else {
                success(@"已成功抢票");
            }
        } else {
            failure(responseObject[@"resultMsg"]?responseObject[@"resultMsg"]:@"支付失败");
        }
    } failureHandler:^(NSError *error) {
        failure(error.localizedDescription);
    }];
}
@end
